from dataclasses import dataclass
import os, sys, re, codecs, binascii, datetime, pickle

from app.lodger2.lodger import Lodger
from app.lodger2.lodger import LodgerItem
from flask import render_template
from flask import g

from app.lodger2 import bp

def GetLodger():
    if 'lodger' not in g:
        g.lodger = Lodger()
    return g.lodger

@bp.route("/")
def lodgerindex():
    return GetLodger().ShowLodger()

@bp.route("/showform/<int:id>")
def showform(id):
    return GetLodger().ShowForm(id)

@bp.route("/delete/<int:id>")
def deleteitem(id):
    return GetLodger().Delete(id)

@bp.route("/add", methods=['POST'])
def add():
    return GetLodger().Add()

@bp.teardown_request
def teardown_lodger(ctx):
    GetLodger().storage.Store()

